import { Component, OnInit } from '@angular/core'
import * as moment from 'moment'

moment.locale('zh-cn')

@Component({
  selector: 'app-calandar-sample',
  templateUrl: './calandar-sample.component.html',
  styleUrls: [ './calandar-sample.component.css' ]
})
export class CalandarSampleComponent implements OnInit {
  a = moment()
  b = this.a.clone().startOf('month')
  c = this.b.clone().startOf('week')

  monthly
  monthly2

  constructor() {
    this.monthly = new Monthly()
    this.monthly2 = new Monthly(2)
  }

  ngOnInit() {
  }

}

class Monthly {
  private _m

  get thisNow() {
    return this._m.clone()
  }

  get month(): number {
    return this._m.month() + 1
  }

  get firstDayOfMonth() {
    return this._m.clone().startOf('month')
  }

  get lastDayOfMonth() {
    return this._m.clone().endOf('month')
  }

  get firstDayOfFirstWeek() {
    return this.firstDayOfMonth.clone().startOf('week')
  }

  get lastDayOfLastWeek() {
    return this.lastDayOfMonth.clone().endOf('week')
  }

  constructor(month?: number) {
    const m = moment()
    this._m = month ? m.month(month - 1) : m
  }
}
